package com.hjn.springboot.springbootservlet.servlet;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/**
 * @author huaijn
 * @date 2022/5/12 /0012-13:58
 * @description todo
 */
public class JavaHttpClient {

  public static void main(String[] args) {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet("http://192.168.3.235:8003/zentao/bug-browse-4--all.html");
    try (CloseableHttpResponse response = httpClient.execute(httpGet);) {
//      httpGet.set
//      获取响应体
      HttpEntity entity = response.getEntity();
      StatusLine statusLine = response.getStatusLine();
      System.out.println("响应状态-----" + statusLine);
      if (entity != null) {
        System.out.println("响应内容的长度：" + entity.getContentLength());
        System.out.println("响应内容为：" + EntityUtils.toString(entity));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}
